<template>
<div class='chat-body-ai'>
  <dl class="other-wrap">
    <div class="time">{{date}}</div>
    <div class="header" :class="{'on':hederDid}" @mouseover='mouseoverEvent' @mouseout='mouseoutEvent'></div>
    <div class='other-info-right'>
      <div class="name">点点</div>
      <div class="msg"> hi </div>
    </div>
  </dl>
  <template v-for="msgObj in Chat.aiMsgArr">
    <self-msg-ai v-if="msgObj.userid===Chat.Uid" :msg="msgObj.msg"></self-msg-ai>
    <dl v-if="msgObj.userid===Chat.Uid" class="other-wrap">
      <div class="time">{{date}}</div>
      <div class="header" :class="{'on':hederDid}" @mouseover='mouseoverEvent' @mouseout='mouseoutEvent'></div>
      <div class='other-info-right'>
        <div class="name">点点</div>
        <div class="msg">{{msgObj.aimsg}}</div>
      </div>
    </dl>
  </template>
</div>
</template>
<script>
import SelfMsgAi from './SelfMsgAi'
import Chat from '../api/client'
export default {
  name: 'chat-body-ai',
  data () {
    return {
      date: '',
      Chat: Chat,
      hederDid: false
    }
  },
  mounted () {
    this.$nextTick(function () {
      if (!localStorage.name) {
        this.$router.push({path: '/'})
      }
      var date = new Date()
      this.date = date.getFullYear() + '-' + getStr(date.getMonth() + 1) + '-' + getStr(date.getDate()) + ' ' + getStr(date.getHours()) + ':' + getStr(date.getMinutes()) + ':' + getStr(date.getSeconds())
      function getStr (str) {
        if (str < 10) {
          str = '0' + str
        }
        return str
      }
    })
  },
  components: {
    SelfMsgAi
  },
  methods: {
    mouseoverEvent () {
      this.hederDid = true
    },
    mouseoutEvent () {
      this.hederDid = false
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .chat-body-ai{
    overflow:auto;
    position:absolute;
    top:50px;
    bottom:220px;
    width:61%;
    padding:2%;
    right:5%;
    background:#fff;
  }
  .chat-body-ai h1{
    text-align:center;
    font-size:18px;
    border-bottom:1px solid red;
  }
  .chat-box{
    position:absolute;
    top:50px;
    bottom:0;
    overflow-y:hidden;
  }
  .other-wrap{
    overflow:hidden;
    padding:20px 5px;
    overflow:hidden;
  }
  .other-wrap .header{
    border-radius:50%;
    float:left;
    line-height:1.5;
    width:50px;
    height:50px;
    background:url(../assets/img/did.gif) no-repeat scroll 0 0;
    background-size:cover;
  }
  .other-wrap .header.on{
    background:url(../assets/img/did2.gif) no-repeat scroll 0 0;
    background-size:cover;
  }
  .other-wrap .other-info-right{
    float:left;
    max-width:66%;
    margin-left:10px;
  }
  .other-wrap .time{
    text-align:left;
    font-size:12px;
    color:#999;
    margin-bottom:10px;
  }
  .other-wrap .name{
    font-size:12px;
    color:#666;
    margin:0 0 5px;
  }
  .other-wrap .msg{
    background:#95BEE4;
    color:#fff;
    padding:10px 20px;
    border-top-left-radius:10px;
    border-bottom-right-radius:10px;
    border-top-right-radius:35px;
    border-bottom-left-radius:35px;
  }
</style>
